home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 1.1 / SGI EnlightenDSM 1.1.iso / dec3240 / install.z / install / bin / .deinstall next >
Text File  |  1998-06-30  |  12KB  |  515 lines

  1. #!/bin/sh
  2. #
  3. # Script: .deinstall
  4. #
  5. # deinstall does the following:
  6. #
  7. # 1) stops all Enlighten daemons 
  8. # 2) removes rc references entered by e_putrc
  9. # 3) removes the dbenl and informix user accounts
  10. # 4) removes the enlighten and emd directories 
  11. # 5) removes the /etc/enlighten file
  12. #
  13. # grep for 'Main' for the start of the script.
  14. #
  15. # Copyright (c) 1990-1998 Enlighten Software Solutions, Inc.
  16. # All Rights Reserved.
  17. #
  18. # 1aug96 mrm
  19. # 14jan97 mrm - incorporated AIX rc.nfs fix
  20. # 23jan97 mrm - added OSF support
  21. # 23jan97 mrm - moved rc references to rc3.d where applicable.
  22.  
  23. PATH=/bin:/usr/bin:/etc:/usr/ucb:/usr/bsd:/usr/etc:$PATH
  24. export PATH
  25.  
  26. # OS-specific setup
  27.  
  28. case "`echo 'a\c'`" in
  29.     'a\c') 
  30.         ECHO="echo -n"
  31.         NO_NL=""
  32.         ;;
  33.     * ) 
  34.         ECHO="echo"
  35.         NO_NL="\c"
  36.         ;;
  37. esac
  38.  
  39. PSOPTS="-e"
  40. PIDCOLUMN=1
  41.  
  42. if [ "$OS" = "SunOS" ]; then
  43.     case "$REV" in
  44.         4.1.* )
  45.             PSOPTS="-axuww"
  46.             PIDCOLUMN=2
  47.             ;;
  48.     esac
  49. fi
  50.  
  51. errorCheck () {
  52.     #
  53.     # errorCheck can be used for all commands except grep
  54.     #
  55.     if [ $? -ne 0 ] ; then
  56.         echo "$appName: Fatal: Could not deinstall Enlighten." 1>&2
  57.         exit 1
  58.     fi
  59. }
  60.  
  61. errorCheck2 () {
  62.     #
  63.     # errorCheck can be used for grep, which returns 2 on error
  64.     #
  65.     if [ $? -eq 2 ] ; then
  66.         echo "$appName: Fatal: Could not deinstall Enlighten." 1>&2
  67.         exit 1
  68.     fi
  69. }
  70.  
  71. should_i_continue () {
  72.     $ECHO "$appName: [y|n|exit] (default is 'y') > $NO_NL"
  73.     read response;
  74.     case "$response" in
  75.         "" | y* | Y* )
  76.             CONTINUE=yes
  77.             ;;
  78.         n* | N* )
  79.             echo "$appName: Deinstallation of Enlighten will not be complete."
  80.             CONTINUE=no 
  81.             ;;
  82.         * )
  83.             echo "$appName: Exitting."
  84.             echo
  85.             exit 2
  86.             ;;
  87.     esac
  88. }
  89.  
  90. VerifyUserIsRoot () {
  91.     USER_ID=`id | tr "\(" "=" | cut "-d=" -f2`
  92.      
  93.     if [ ! $USER_ID = 0 ] ; then
  94.         echo
  95.         echo "### $appName must be run by the 'root' superuser."
  96.         echo "    Please login as root and try again."
  97.         echo
  98.         echo "Exitting.  All partitions left untouched."
  99.         echo
  100.         exit 2
  101.     fi
  102. }
  103.  
  104. VerifyScriptIsRunningFromTmpDir () {
  105.     if [ ! "$fullAppDirName" = "$ENLIGHTEN" -o ! `pwd` = "$ENLIGHTEN" ] ; then
  106.         if [ -f $ENLIGHTEN/$appName ] ; then
  107.             rm /$ENLIGHTEN/$appName
  108.         fi
  109.         cp $fullAppDirName/$appName $ENLIGHTEN/$appName
  110.         chmod 700 $ENLIGHTEN/$appName
  111.  
  112.         if [ -x $ENLIGHTEN/$appName ] ; then
  113.             echo "Please cd into $ENLIGHTEN and invoke ./$appName to deinstall Enlighten."
  114.             exit 0
  115.         else
  116.             echo "$appName: Fatal: Could not copy $appName to $ENLIGHTEN."
  117.             echo "$appName: This script must be copied into $ENLIGHTEN to run."
  118.             exit 1
  119.         fi
  120.     fi
  121. }
  122.  
  123. #
  124. # Put the pid(s) of process(es) from $procs into $pid
  125. #
  126. getPid() {
  127.  
  128.     # Search for:
  129.     # bin/renld -v 0
  130.     # renld -v 0
  131.     # renld
  132.  
  133.     psList=`ps $PSOPTS | egrep -v "$appName|grep"`
  134.     pid=""
  135.  
  136.     for i in $procs ; do
  137.         newpid=`echo "$psList" | egrep "\/$i | $i |[\/ ]$i$" | \
  138.             sed -e 's/^  *//' -e 's/ .*//'`
  139.         pid="$pid $newpid"
  140.         #echo $i is pid $newpid.
  141.     done
  142.     pid=`echo $pid`
  143. }
  144.  
  145. #
  146. # Kill process(es) in $procs.
  147. #
  148. killProcs() {
  149.     getPid $procs
  150.     if [ -n "$pid" ] ; then
  151.         if [ "$KILLOPTS" = "-9" -o "$KILLOPTS" = "-KILL" ] ; then
  152.             echo "$appName: Killing the following processes:"
  153.         else
  154.             echo "$appName: Stopping the following processes:"
  155.         fi
  156.         echo "$psList" | grep PID
  157.         for i in $pid ; do
  158.             echo "$psList" | grep $i
  159.             kill $KILLOPTS $i
  160.         done
  161.     fi
  162. }
  163.  
  164. export procs pid psList KILLOPTS
  165.  
  166. StopENlightenProcesses () {
  167.  
  168.     KILLOPTS="-9"
  169.     procs="xenln sm enl_xinstall renldc"
  170.     killProcs
  171.  
  172.     if [ -x $ENLIGHTEN/bin/stop_enl_daemons ] ; then
  173.         $ENLIGHTEN/bin/stop_enl_daemons
  174.         errorCheck
  175.     elif [ -x $EMD_DIR/bin/stop_enl_daemons ] ; then
  176.         $EMD_DIR/bin/stop_enl_daemons
  177.         errorCheck
  178.     else
  179.         echo "$appName: 'stop_enl_daemons' was missing."
  180.         echo "$appName: 'rm' may fail if Enlighten processes are still active."
  181.     fi
  182. }
  183.  
  184. cleanup_rc() {
  185.  
  186.     if [ -f $RC_DIR/$RC_FILE ] ; then
  187.         echo "$appName: Remove Enlighten references from $RC_DIR/$RC_FILE?"
  188.         should_i_continue
  189.         if [ $CONTINUE = yes ] ; then
  190.             if [ "$RC_FILE" = "S92startenl" -o "$RC_FILE" = "S920enlighten" ] ; then
  191.                 mv $RC_DIR/$RC_FILE /tmp/$RC_FILE.old ; errorCheck
  192.                 echo "$appName: $RC_DIR/$RC_FILE was archived to /tmp/$RC_FILE.old"
  193.             elif [ "$RC_FILE" = "enlighten" ] ; then
  194.                 mv $RC_DIR/$RC_FILE /tmp/$RC_FILE.old ; errorCheck
  195.                 echo "$appName: $RC_DIR/$RC_FILE was archived to /tmp/$RC_FILE.old"
  196.                 rm $LINK_DIR/$LINK_FILE ; errorCheck
  197.                 echo "$appName: $LINK_DIR/$LINK_FILE was removed."
  198.                 rm $LINK_DIR_STOP/$LINK_FILE_STOP ; errorCheck
  199.                 echo "$appName: $LINK_DIR_STOP/$LINK_FILE_STOP was removed."
  200.             else
  201.                 cp $RC_DIR/$RC_FILE $RC_DIR/$RC_FILE.old
  202.                 errorCheck
  203.                 echo "$appName: $RC_DIR/$RC_FILE was archived to $RC_DIR/$RC_FILE.old"
  204.                 egrep -v "S92startenl|start_enl_daemons|start_dsmld" $RC_DIR/$RC_FILE > $RC_DIR/$RC_FILE.new
  205.                 errorCheck2
  206.  
  207.                 mv $RC_DIR/$RC_FILE.new $RC_DIR/$RC_FILE
  208.                 errorCheck
  209.  
  210.                 chown root $RC_DIR/$RC_FILE
  211.                 errorCheck
  212.  
  213.                 chmod 744 $RC_DIR/$RC_FILE
  214.                 errorCheck
  215.             fi
  216.         fi
  217.     fi
  218. }
  219.  
  220. RemoveStartupScripts () {
  221.     
  222.     # Remove rc references
  223.     case `uname -s` in
  224.         OSF1 )
  225.             RC_DIR=/sbin/init.d
  226.             RC_FILE=enlighten
  227.             LINK_FILE=S920enlighten
  228.             LINK_DIR=/sbin/rc3.d
  229.             LINK_FILE_STOP=K12enlighten
  230.             LINK_DIR_STOP=/sbin/rc0.d
  231.             ;;
  232.         HP-UX ) 
  233.             case `uname -r` in
  234.                 ?.10.* )
  235.                     RC_DIR=/sbin/init.d ; export RC_DIR
  236.                     RC_FILE=enlighten ; export RC_FILE
  237.                     LINK_DIR=/sbin/rc2.d ; export LINK_DIR
  238.                     LINK_FILE=S920enlighten ; export LINK_FILE
  239.                     LINK_FILE_STOP=K12enlighten ; export LINK_FILE_STOP
  240.                     LINK_DIR_STOP=/sbin/rc0.d ; export LINK_DIR_STOP
  241.                     ;;
  242.                 * )
  243.                     RC_DIR=/etc ; export RC_DIR
  244.                     RC_FILE=rc ; export RC_FILE
  245.                     ;;
  246.             esac
  247.             ;;
  248.         AIX )
  249.             # There may be entries in rc.nfs or rc.tcpip.
  250.             RC_DIR=/etc ; export RC_DIR
  251.             RC_FILE=rc.tcpip ; export RC_FILE
  252.             cleanup_rc
  253.  
  254.             RC_DIR=/etc ; export RC_DIR
  255.             RC_FILE=rc.nfs ; export RC_FILE
  256.             ;;
  257.         IRIX* )
  258.             RC_DIR=/etc/init.d
  259.             RC_FILE=enlighten
  260.             LINK_FILE=S920enlighten
  261.             LINK_DIR=/etc/rc2.d
  262.             LINK_FILE_STOP=K12enlighten
  263.             LINK_DIR_STOP=/etc/rc0.d
  264.             ;;
  265.         * )
  266.             if [ -d /etc/rc2.d ] ; then
  267.                 RC_DIR=/etc/rc2.d ; export RC_DIR
  268.                 RC_FILE=S92startenl ; export RC_FILE
  269.                 cleanup_rc
  270.                 RC_FILE=S920enlighten ; export RC_FILE
  271.             else
  272.                 RC_DIR=/etc ; export RC_DIR
  273.                 RC_FILE=rc.local ; export RC_FILE
  274.             fi
  275.             ;;
  276.     esac
  277.  
  278.     cleanup_rc
  279. }
  280.  
  281. RemoveEMDUsers () {
  282.  
  283.     # remove the dbenl and informix user accounts
  284.     #
  285.     # (Only remove dbenl and informix if this host has an emd_dir.)
  286.  
  287.     if [ ! -z "$EMD_DIR" ] ; then
  288.         
  289.         # Remove the dbenl accounts
  290.  
  291.         if [ -z "`egrep '^dbenl:' /etc/passwd /etc/group`" ] ; then
  292.             echo "$appName: Error: The 'dbenl' user was missing."
  293.         else
  294.             echo "$appName: Remove the 'dbenl' user and group account?"
  295.             should_i_continue
  296.             if [ $CONTINUE = yes ] ; then
  297.                 UMASK=`umask`
  298.                 umask 077
  299.                 for i in /etc/passwd /etc/group /etc/shadow ; do
  300.                     if [ -f $i ] ; then
  301.                         cp -p $i $i.old1 ; errorCheck
  302.                         echo "$appName: $i was archived to $i.old1."
  303.  
  304.                         egrep -v "^dbenl:" $i > $i.new
  305.                         errorCheck2
  306.                         mv $i.new $i ; errorCheck
  307.                         case "$i" in
  308.                             /etc/shadow)
  309.                             chown root $i ; errorCheck
  310.                             chmod 400 $i ; errorCheck
  311.                             ;;
  312.                             *)
  313.                             chown root $i ; errorCheck
  314.                             chmod 644 $i ; errorCheck
  315.                             ;;
  316.                         esac
  317.                     fi
  318.                 done
  319.                 umask $UMASK
  320.  
  321.                 # Remove AIX password references in /etc/security/passwd
  322.  
  323.                 if [ -f /etc/security/passwd ] ; then
  324.                     cp -p /etc/security/passwd /etc/security/passwd.old1 
  325.                     errorCheck
  326.                     echo "$appName: /etc/security/passwd was archived to /etc/security/passwd.old1."
  327.                     awk 'BEGIN  { FS = ":" } \
  328.                         NF > 1  { flag = 0 } \
  329.                         /dbenl/ { flag = 1 } \
  330.                         { if ( flag == 0 ) print }' /etc/security/passwd.old1 \
  331.                         > /etc/security/passwd.new
  332.                     errorCheck
  333.                     mv /etc/security/passwd.new /etc/security/passwd ; errorCheck
  334.                     chown root /etc/security/passwd ; errorCheck
  335.                     chgrp security /etc/security/passwd ; errorCheck
  336.                     chmod 400 /etc/security/passwd ; errorCheck
  337.                 fi
  338.             fi
  339.         fi
  340.  
  341.         # Remove the informix accounts
  342.  
  343.         if [ -z "`egrep '^informix:' /etc/passwd /etc/group`" ] ; then
  344.             echo "$appName: Error: The 'informix' user was missing."
  345.         else
  346.             echo "$appName: Remove the 'informix' user and group account?"
  347.             should_i_continue
  348.             if [ $CONTINUE = yes ] ; then
  349.                 UMASK=`umask`
  350.                 umask 077
  351.                 for i in /etc/passwd /etc/group /etc/shadow ; do
  352.                     if [ -f $i ] ; then
  353.                         cp -p $i $i.old2 ; errorCheck
  354.                         echo "$appName: $i was archived to $i.old2."
  355.                         egrep -v "^informix:" $i > $i.new
  356.                         errorCheck2
  357.                         mv $i.new $i ; errorCheck
  358.                         case "$i" in
  359.                             /etc/shadow)
  360.                             chown root $i ; errorCheck
  361.                             chmod 400 $i ; errorCheck
  362.                             ;;
  363.                             *)
  364.                             chown root $i ; errorCheck
  365.                             chmod 644 $i ; errorCheck
  366.                             ;;
  367.                         esac
  368.                     fi
  369.                 done
  370.                 umask $UMASK
  371.  
  372.                 # Remove AIX password references in /etc/security/passwd
  373.  
  374.                 if [ -f /etc/security/passwd ] ; then
  375.                     cp /etc/security/passwd /etc/security/passwd.old2 
  376.                     errorCheck
  377.                     echo "$appName: /etc/security/passwd was archived to /etc/security/passwd.old2."
  378.                     awk 'BEGIN  { FS = ":" } \
  379.                         NF > 1  { flag = 0 } \
  380.                         /informix/ { flag = 1 } \
  381.                         { if ( flag == 0 ) print }' /etc/security/passwd.old2 \
  382.                         > /etc/security/passwd.new
  383.                     errorCheck
  384.                     mv /etc/security/passwd.new /etc/security/passwd ; errorCheck
  385.                     chown root /etc/security/passwd ; errorCheck
  386.                     chgrp security /etc/security/passwd ; errorCheck
  387.                     chmod 400 /etc/security/passwd ; errorCheck
  388.                 fi
  389.             fi
  390.         fi
  391.     fi
  392. }
  393.  
  394. RemoveGroupAccount () {
  395.  
  396.     # remove the enldsm entry from group file
  397.     #
  398.     if [ -z "`egrep '^enldsm:' /etc/group`" ] ; then
  399.     echo "$appName: Error: The 'enldsm' group entry was missing."
  400.     else
  401.     echo "$appName: Remove the 'enldsm' group?"
  402.     should_i_continue
  403.     if [ $CONTINUE = yes ] ; then
  404.         for i in /etc/group ; do
  405.         if [ -f $i ] ; then
  406.             cp -p $i $i.old1 ; errorCheck
  407.             echo "$appName: $i was archived to $i.old1."
  408.  
  409.             egrep -v "^enldsm:" $i > $i.new
  410.             errorCheck2
  411.             mv $i.new $i ; errorCheck
  412.             chown root $i ; errorCheck
  413.             chmod 644 $i ; errorCheck
  414.         fi
  415.         done
  416.     fi
  417.     fi
  418. }
  419.  
  420.  
  421. RemoveENlightenDirectories () {
  422.  
  423.     # Remove the Enlighten and EMD directories 
  424.     if [ ! -z "$ENLIGHTEN" -a -d "$ENLIGHTEN" ] ; then
  425.         echo "$appName: Recursively remove the Enlighten directory $ENLIGHTEN?"
  426.         should_i_continue
  427.         if [ $CONTINUE = yes ] ; then
  428.             rm -rf $ENLIGHTEN/* $ENLIGHTEN/.data
  429.             errorCheck
  430.         fi
  431.     fi
  432.  
  433.     if [ ! -z "$EMD_DIR" -a -d "$EMD_DIR" ] ; then
  434.         echo "$appName: Recursively remove the EMD directory $EMD_DIR?"
  435.         should_i_continue
  436.         if [ $CONTINUE = yes ] ; then
  437.             rm -rf $EMD_DIR
  438.             errorCheck
  439.         fi
  440.     fi
  441.  
  442.     if [ -f /etc/enlighten -a "$CONTINUE" = "yes" ] ; then
  443.         rm /etc/enlighten
  444.         errorCheck
  445.         echo "$appName: Removed /etc/enlighten."
  446.     fi
  447. }
  448.  
  449. #
  450. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  451. # Main Program
  452. #
  453.  
  454. appName=`basename $0`
  455. appDirName=`dirname $0`
  456. fullAppDirName=`cd $appDirName ; pwd`
  457.  
  458. if [ ! -f /etc/enlighten ] ; then
  459.     echo
  460.     echo "$appName: ### The /etc/enlighten file is missing."
  461.     echo "$appName: ### Enlighten is probably not installed on this host."
  462.     echo "$appName: Exitting."
  463.     exit 0
  464. else
  465.     ENLIGHTEN=`egrep "^enlighten=" /etc/enlighten | cut "-d=" -f2-` 
  466.     EMD_DIR=`egrep "^emd_dir=" /etc/enlighten | cut "-d=" -f2-`
  467.     export ENLIGHTEN EMD_DIR
  468. fi
  469.  
  470. VerifyUserIsRoot
  471. VerifyScriptIsRunningFromTmpDir
  472.  
  473. $ECHO "$appName: Are you sure you want to deinstall Enlighten? [y|n|exit] $NO_NL" 
  474. read response;
  475. case "$response" in
  476.     y* | Y* ) ;;
  477.     * )
  478.         echo "$appName: Cancelled."
  479.         exit 0
  480.         ;;
  481. esac
  482.  
  483. # Because the following are reversible, don't ask.
  484.  
  485. if [ -n "$EMD_DIR" ] ; then
  486.     if [ ! -f $EMD_DIR/FLEXlm/lmutil ] ; then
  487.         echo "$appName: Unable to find $EMD_DIR/FLEXlm/lmutil."
  488.         echo "$appName: Unable to stop license daemons."
  489.     else
  490.         echo ""
  491.         echo "$appName: Stopping license daemons."
  492.         su dbenl -c "$EMD_DIR/FLEXlm/lmutil lmdown -c $EMD_DIR/FLEXlm/license.dat -q"
  493.         echo ""
  494.     fi
  495. fi
  496.  
  497. StopENlightenProcesses
  498. RemoveStartupScripts
  499.  
  500. RemoveGroupAccount
  501. RemoveEMDUsers
  502. RemoveENlightenDirectories
  503.  
  504. echo "$appName: Finished."
  505. echo
  506.  
  507. echo "All Enlighten files have been deinstalled except for"
  508. echo "the .deinstall script.  Please run the following commands"
  509. echo "to complete the deinstall:"
  510. echo "cd /"
  511. echo "rm -r $ENLIGHTEN"
  512.  
  513. exit 0
  514.  
  515.